package models

import (
	"github.com/jinzhu/gorm"
	"kop/modules/role/entity"
)

func GetRoleEvent(dB *gorm.DB, roleID int32) (*entity.RoleEvent, error) {

	var event = entity.RoleEvent{
		RoleID:     roleID,
		EventIDArr: []int32{},
	}

	var err = dB.First(&event).Error
	if err != nil && err != gorm.ErrRecordNotFound {
		panic(err)
	}

	return &event, err
}

func CreateRoleEvent(dB *gorm.DB, roleEvent *entity.RoleEvent) {

	if err := dB.Create(roleEvent).Error; err != nil {
		panic(err)
	}
}

func SaveRoleEvent(dB *gorm.DB, event *entity.RoleEvent) {

	if err := dB.Save(&event).Error; err != nil {
		panic(err)
	}
}
